#include <EB0/EB0.h>

namespace EB0
{
namespace Tasks
{
#pragma region Constructor / Destructor
	// Default Constructor
	GameTask::GameTask()
	{
		// Default values
		mRepeatedFunc = 0;
		mRunning = false;
	}

	// Constructor with function pointer
	GameTask::GameTask(void (*repeatedFunc)(float))
	{
		// Set repeated function pointer
		mRepeatedFunc = repeatedFunc;

		// Default values
		mRunning = false;
	}

	// Destructor
	GameTask::~GameTask()
	{
		// Reset values
		mRepeatedFunc = 0;
		mRunning = false;
	}
#pragma endregion

#pragma region Start / Stop
	// Start the task (called through TaskManager)
	void GameTask::start()
	{
		// Perform onStart() function
		onStart();

		// Enable running flag
		mRunning = true;
	}

	// Stop the task (called through TaskManager)
	void GameTask::stop()
	{
		// Perform onStop() function
		onStop();

		// Disable running flag
		mRunning = false;
	}
#pragma endregion

#pragma region Update
	// Update
	void GameTask::update(float dt)
	{
		// Only update if the task is running
		if (mRunning)
		{
			// Repeated function pointer or virtual function?
			if (mRepeatedFunc)
				(*mRepeatedFunc)(dt);
			else
				updateTask(dt);
		}
	}
#pragma endregion

#pragma region Virtual Functions
	// On Start
	void GameTask::onStart()
	{
		printf("Game Task On Start\r\n");
	}

	// On Stop
	void GameTask::onStop()
	{
		printf("Game Task On Stop\r\n");
	}

	// Update Task
	void GameTask::updateTask(float dt)
	{
		printf("Update Task %.4f\r\n", dt);
	}
#pragma endregion
}
}